package com.tang.cometTest.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.lang.RandomStringUtils;

import com.tang.cometTest.entity.LoginVO;
import com.tang.cometTest.util.JDBCUtil;

public class UserDao {
	
	public LoginVO login(String username, String password) {
		StringBuffer sql = new StringBuffer("select username from user wehre username=? and password=?");
		Connection conn = JDBCUtil.getConnection();
		LoginVO vo = new LoginVO();
		try {
			PreparedStatement pstmt = conn.prepareStatement(sql.toString());
			pstmt.setString(1, username);
			pstmt.setString(2, password);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				vo.setSessionID(RandomStringUtils.randomNumeric(8));
				vo.setUsername(rs.getString("username"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return vo;
	}
}
